import React, {Component} from "react";
import Search from "../../../component/Search";
import DetailHead from "../components/LessonDetailHead";
import DetailBody from '../components/LessonDetailBody';

class LessonDetail extends Component{

    state = {
        searchConfig: {
            columns: [
                {
                    type: 'Input',
                    name: 'classhourName',
                    placeholder: '课时名称',
                }
            ]
        },
        tableConfig: {
            pagination: {
                page: 1,
                limit: 5
            },
            params: {
                link: {
                    classCode: this.props.location.state.code,
                    curriculumId: this.props.match.params.id
                },
                sortName: "start_time",
                sortType: "desc"
            },
            request: {
                method: 'post',
                url: '/Curriculum/getCurriculumInfo',
                headers: {}
            }
        }
    };

    render() {
        return (
            <div className="table-detail">
                <DetailHead />
                <Search config={this.state.searchConfig} search={this.getSearchParams} />
                <DetailBody config={this.state.tableConfig} onRef={(ref) => { this.child = ref }} />
            </div>
        )
    }

    getSearchParams (params){
        const { location, match } = this.props;
        this.setState((state) => {
            state.params.link = Object.assign({
                classCode: location.state.code,
                curriculumId: match.params.id
            }, params);
            state.pagination = {
                page: 1,
                limit: 5
            };
            return state
        }, () => {
            this.child.getDataList({
                ...this.state.pagination
            })
        })
    }

}

export default LessonDetail;